<template>
    <div>
        <div>
            <p>用户：<input type="text" v-model="a"></p>
            <p><input type="button" @click="reds()" value="登录"></p>
        </div>
        <div>
            <table align="center">
                <tr>
                    <td>新闻标题：</td> <td>新闻评论</td><td>评论</td>
                </tr>
                <tr v-for="(i,j) in xinwenlist" :key="j">
                    <td>{{i.title}}</td>
                    <td>{{i.content}}</td>
                    <td><input type="button" @click="pinglun(i.id)" value="评论"></td>
                </tr>
            </table>
            <div v-for="(i,j) in pinshoulist" :key="j">
                <li>{{i.title}}</li>
                <li>{{i.content}}</li>
            <p><input type="text" v-model="content"></p>
            <p><input type="button" @click="tianjia()"></p>
            </div>
        </div>
    </div>
</template>

<script>
import {RI_user_red,RI_xinwen_show,RI_pinglun_red,RI_ping_res} from '../axios_send/api.js'
export default {
    name:"xinwen",
    data(){
        return{
            a:"",
            xinwenlist:"",
            pinshoulist:"",
            content:"",
        }
    },
    methods:{
        reds(){
            var data={"a":this.a}
            console.log(data)
            RI_user_red(data)
            .then(res=>{
                console.log(res)
                if(res.data.code==200){
                sessionStorage.setItem("name",res.data.data)
            }
            })
        },
        xinwen_show(){
            RI_xinwen_show()
            .then(res=>{
                console.log(res);
                this.xinwenlist = res.data
            })
        },
        pinglun(id){
            console.log(id);
            RI_pinglun_red(id)
            .then(res=>{
                console.log(res)
                this.pinshoulist = res.data
            })
        },
        tianjia(){
            var data = {"content":this.content}
            RI_ping_res(data)
            .then(res=>{
                console.log(res)
            })
        }       
    },
    created(){
        this.xinwen_show()
    }
}
</script>

<style>

</style>
